package com.hailian.fintech.hlpayoffserver.web;


import com.hailian.fintech.hlcomm_interfaceserver.result.ResultInfo;
import com.hailian.fintech.hlpayoffserver.service.IWeixin_payService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wk
 * @since 2020-05-27
 */
@Controller
@RequestMapping("/weixin_pay")
public class Weixin_payController {

    @Autowired
    private IWeixin_payService iWeixin_payService;
    /**
     * 微信扫码支付统一下单
     */
    @RequestMapping(value = "/WxPayUnifiedorder", method = RequestMethod.GET)
    @ResponseBody
    public Object WxPayUnifiedorder(String out_trade_no) throws Exception{
        HashMap<String,Object> map = new HashMap<String,Object>();
        String codeUrl = iWeixin_payService.weixin_pay(out_trade_no);
        map.put("codeUrl",codeUrl);
        return new ResultInfo().success(map);
    }
    /**
     * 生成二维码图片并直接以流的形式输出到页面
     * @param code_url
     * @param response
     */
    @RequestMapping("qr_codeImg")
    @ResponseBody
    public void getQRCode(String code_url, HttpServletResponse response){
        iWeixin_payService.encodeQrcode(code_url, response);
    }
    @RequestMapping(value = "/weixinNotify", method = RequestMethod.POST)
    @ResponseBody
    public void weixinNotify(HttpServletRequest request, HttpServletResponse response) throws Exception{
        System.out.println("支付回调方法开始！");
        HashMap<String,Object> map = new HashMap<String,Object>();
        iWeixin_payService.weixin_notify(request, response);
        System.out.println("支付回调方法结束！");
    }





}

